home *** CD-ROM | disk | FTP | other *** search
/ Programming Sound Cards / Programming Sound Cards.iso / sound_56 / mono.inc < prev    next >
Text File  |  1995-01-01  |  8KB  |  212 lines

  1. mono_tick0:    cmp   [patterndelay],0
  2.                je    nodelay     ; or pattern delay done ...
  3.                dec   [patterndelay]
  4.                jz    nodelay
  5.                dec   [curline]
  6. nodelay:       setborder 4
  7.                call near ptr [READNEWNOTES]
  8.                setborder 1
  9.                jmp  continuecalc
  10.  
  11. aNewtick:      mov           ax,[BPT]
  12.                mov           [TickBytesLeft],ax
  13.                mov           [calleffects],1
  14.                cmp           [curtick],1
  15.                jbe           mono_tick0
  16.                dec           [curtick]
  17.                jmp           continuecalc
  18.  
  19. calc_mono_tick PROC NEAR
  20.                push          bp
  21.                ; first fill tickbuffer with ZERO = 2048+offset post8bit
  22.                ; for 16bit play then ofcourse a bit different value ...
  23.                ; just only for 8bit play mode
  24.                mov           ax,word ptr [offset tickbuffer +2]
  25.                mov           es,ax
  26.                mov           ax,2048+offset post8bit
  27.                xor           di,di
  28.                mov           cx,[DMArealBufsize+2]
  29.                setborder     3
  30.                rep stosw
  31.                setborder     1
  32.                mov           [nextPosition],0
  33.                mov           [calleffects],0
  34.                cmp           [TickBytesLeft],0
  35.                jz            aNewTick
  36. continuecalc:
  37.                mov           ax,word ptr [offset tickbuffer +2]
  38.                mov           es,ax 
  39.                cmp           [EndOfSong],1
  40.                je            afterall
  41.                mov           al,[usedchannels]
  42.                mov           [curchannel],al
  43.                
  44.                ; number of ticks we calc for every tick :
  45.                mov           ax,[TickBytesLeft]
  46.                mov           cx,[DMArealBufsize+2]
  47.                sub           cx,[nextPosition]
  48.                cmp           cx,ax
  49.                jbe           cantfinishTick
  50.                mov           cx,ax     ; finish that Tick and loop to fill the whole tickbuffer
  51. cantfinishTick:
  52.                mov           [sample2calc],cx
  53.                cmp           cx,0
  54.                je            afterall
  55.  
  56.                xor           bp,bp
  57. chnLoop:       cmp           ds:[channel.channeltyp+bp],0
  58.                je            nextchannel
  59.                cmp           ds:[channel.channeltyp+bp],2
  60.                ja            nextchannel
  61.                cmp           [calleffects],0
  62.                je            noeff
  63.                ; do effects for this channel :
  64.                mov           al,[curtick]
  65.                cmp           al,[curspeed]
  66.                je            noeff_forfirst
  67. doeff:         mov           bx,ds:[channel.command+bp]
  68.                cmp           bx,255*2
  69.                je            noeff
  70.                call          [effects + bx]
  71. noeff:
  72. noeff_forfirst:
  73.                ; check if mixing :
  74.                cmp           ds:[channel.enabled+bp],0
  75.                je            nextchannel
  76.  
  77.                mov           ax,ds:[channel.SampleSEG+bp]
  78.                ; well now check if in EMS :
  79.                cmp           ax,0f000h
  80.                jb            noEMSsample
  81.                and           ax,0fffh
  82.                mov           bx,ax
  83.                mov           di,ds:[channel.sLoopend+bp]
  84.                mov           ax,04400h
  85.                mov           dx,[smpEMShandle]  ; dx = handle
  86. onemorepage:   push          bp bx ax dx di
  87.                ; Set page number:
  88.                int     67h
  89.                cmp     ah,0
  90.                je      noemsprob
  91.                mov     dl,0
  92.                div     dl         ; <- cause a "div by 0" because EMSdriver does not work correct
  93. noemsprob:     pop           di dx ax bx bp
  94.                inc           al
  95.                inc           bx
  96.                sub           di,16*1024
  97.                jnc           onemorepage
  98.                mov           ax,[frameseg]
  99. noEMSsample:   mov           gs,ax
  100.  
  101.                xor           ebx,ebx
  102.                mov           bh,ds:[channel.SampleVol+bp]
  103.  
  104.                lfs           si,[volumetableptr]
  105.  
  106.                mov           si,[nextPosition]
  107.                shl           si,1
  108.                mov           cx,[sample2calc]
  109.  
  110.                mov           edi,ds:[channel.sCurpos+bp]
  111.                rol           edi,16
  112.  
  113.                mov           edx,ds:[channel.sStep+bp]
  114.                rol           edx,16
  115.  
  116.                cmp           di,ds:[channel.sLoopend+bp]
  117.                jae           sampleends1
  118. back2calc1:
  119.                ; ES:SI - pointer to tickbuffer
  120.                ; GS:DI - pointer to sampledata
  121.                ; FS:BX - pointer to volumetable
  122.                ; DX    - decision part of current position in sample
  123.                ; DI    - integer part of current position in sample
  124.                ; BH    - volume of instrument
  125.                ; CX    - number of values to calc
  126.                ; DS,BP - under use, but not in inner loop <- not optimized (hey come on, I just started to code this)
  127.  
  128.                ; jump into innerloop :
  129.                push          bp
  130.                mov           bp,cx
  131.                and           bp,31
  132.                shr           cx,5
  133.                inc           cx
  134.  
  135.                neg           bp
  136.                add           bp,32
  137.  
  138.                cmp           bp,32  ; <- that cost me some minutes to think about :(
  139.                jne           no0
  140.  
  141.                dec           cx
  142.                xor           bp,bp
  143.  
  144. no0:           shl           bp,1
  145.                sub           si,bp
  146.                ;sub           si,bp
  147.  
  148.                add           bp,offset mn_innerloop_tbl
  149.                ; before jump arround =) swap fs,ds
  150.                push         ds fs
  151.                mov          ax,ds
  152.                mov          fs,ax
  153.                pop          ds
  154.                push         ds
  155.                jmp          word ptr fs:[bp]
  156.  
  157. macro_mninner  MACRO no
  158. align 2
  159. mn_inner&no:   mov           bl,gs:[di]
  160.  
  161.                add           edi,edx
  162.                adc           di,0
  163.  
  164.                mov           ax,ds:[ebx+ebx]  ; convert samplevalue with volumetable
  165.  
  166.                add           es:[si+pos],ax     ; mix value to other channels
  167. ENDM
  168.  
  169. tickloop:
  170. z = 0
  171. pos = 0
  172. rept 32        ; I know I'm crazy :) but what we do for fast inner loops ...
  173. macro_mninner %z
  174. z = z + 1
  175. pos = pos + 2
  176. endm
  177.                add           si,32*2
  178.                dec           cx
  179.                jnz           tickloop
  180.  
  181.                pop           fs
  182.                pop           ds
  183.                pop           bp
  184.  
  185. aftercalc:     rol           edi,16
  186.                mov           ds:[channel.sCurpos+bp],edi
  187.  
  188. nextchannel:   add           bp,size channel
  189.                dec           [curchannel]
  190.                jnz           chnLoop
  191.  
  192.                mov           ax,[sample2calc]
  193.                sub           [TickBytesLeft],ax
  194.                add           [nextPosition],ax
  195.                mov           ax,[DMArealBufsize+2]
  196.                cmp           [nextPosition],ax
  197.                jb            aNewTick
  198.  
  199. afterall:      pop           bp
  200.                ret
  201.  
  202. sampleends1:   cmp           ds:[channel.sloopflag+bp],0
  203.                je            no_loopflag1
  204. tryagain1:     sub           di,ds:[channel.sloopEnd+bp]
  205.                add           di,ds:[channel.sloopstart+bp]
  206.                cmp           di,ds:[channel.sloopEnd+bp]
  207.                jae           tryagain1
  208.                jmp           back2calc1
  209. no_loopflag1:  mov           ds:[channel.enabled+bp],0
  210.                jmp           aftercalc
  211.  
  212. calc_mono_tick ENDP